#include <string.h>
#include <iostream>
using namespace std;
class Stack{
public:
    Stack(int capacity)
    :index(-1)
    ,capacity(capacity)
    ,data(new int[capacity]())
    {
    cout<<"构造函数"<<endl;
    }

    ~Stack(){
        delete[] data;
    }
    bool empty();
    bool full();
    void push(int);
    void pop();
    int top();
private:
    int index=-1;
    int capacity;
    int *data;
};

bool Stack::empty(){
return index==-1;
}
bool Stack::full(){
    return index==capacity-1;

}
void Stack::push(int value){
    if(!full()){
    data[++index]=value;
    }
}
void Stack::pop(){
    if(!empty()){
    --index;
    }
}
int Stack::top(){
    return data[index];
}

void test(void){ 
Stack st(10);
st.push(1);
st.push(2);
cout<<st.top()<<endl;
st.pop();
cout<<st.top()<<endl;
}
int main(int argc, char * argv[]){
   test();



    return 0;
}

